package com.sumainfor.pc.market.controller.rentadviser;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.service.RdTenantAskService;
import com.sumainfor.pc.market.service.RdTenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Date 2018年11月7日
 * @Describe 工程部查询房源配置
 */
@RestController
@RequestMapping("/rentadviser/RdTenantController")
public class RdTenantController implements Serializable {
    @Autowired
    private RdTenantService rdTenantService;

    /**
     * 分页查询客户池
     *
     * @param params
     * @param pager
     * @return
     */
    @GetMapping("/getTenantList")
    public JsonResult getTenantList(@RequestParam Map<String, Object> params, Pager pager) {
        JsonResult result = new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout = rdTenantService.getTenantListCount(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, cout);
        }
        List<Map<String, Object>> getCommunityList = rdTenantService.getTenantList(params);
        result = pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }

    /**
     * 签约时根据手机号查询是否有租客存在如果有就修改租客的信息，如果没有就新增租客
     */
    @PostMapping("/saveOrUpdateTenant")
    public JsonResult saveOrUpdateTenant(@RequestBody Map<String, Object> params) {
        JsonResult result = new JsonResult();
        System.out.println("params:" + params);
        Integer count = rdTenantService.saveOrUpdateTenant(params);
        if (count != null) {
            result.put(count);
        } else {
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }

    /**
     * 创建客户的时候先根据手机号查询客户是否已经存在
     */
    @GetMapping("/getTenantByTenMode")
    public JsonResult getTenantByTenMode(@RequestParam Map<String, Object> params) {
        return rdTenantService.getTenantByTenMode(params);
    }

    /**
     * 租后主管发起投诉时根据用户手机号查询到的用户的合同、房屋信息
     */
    @GetMapping("/getTenantInfoByTenMode")
    public JsonResult getTenantInfoByTenMode(@RequestParam Map<String, Object> params) {
        return rdTenantService.getTenantInfoByTenMode(params);
    }

    /**
     * 租后主管投诉列表查询租客的信息和房源归属管家
     */
    @PostMapping("/key/getTenSysUserInfoListForGmio")
    public JsonResult getTenSysUserInfoListForGmio(@RequestBody Map<String, Object> params) {
        JsonResult result = new JsonResult();
        List<Map<String, Object>> lsit = rdTenantService.getTenSysUserInfoListForGmio(params);
        if (lsit != null) {
            result.put(lsit);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /**
     * 服务管家查询已签约的租客列表
     *
     * @param params
     * @param pager
     * @return
     */
    @GetMapping("/getTenantListForGmio")
    public JsonResult getTenantListForGmio(@RequestParam Map<String, Object> params, Pager pager) {
        JsonResult result = new JsonResult();
        String a = params.get("blaStatusList").toString();
        if (a.equals("")) {//审核是否通过
            params.put("blaStatusList", null);
        } else {
            params.put("blaStatusList", a.split(","));
        }
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout = rdTenantService.getTenantListForGmioCount(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, cout);
        }
        List<Map<String, Object>> getCommunityList = rdTenantService.getTenantListForGmio(params);
        result = pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }

    /**
     * 服务管家查询强制退的退租对象
     */
    @PostMapping("/key/getTenantListByTenId")
    public JsonResult getTenantListByTenId(@RequestBody Map<String, Object> params) {
        JsonResult result = new JsonResult();
        List<Map<String, Object>> lsit = rdTenantService.getTenantListByTenId(params);
        if (lsit != null) {
            result.put(lsit);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /**
     * 租赁顾问客户池点击已联系
     */
    @PostMapping("/updateTenantTime")
    public JsonResult updateTenantTime(@RequestBody Map<String, Object> params) {
        return rdTenantService.updateTenantTime(params);
    }

}
